home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
L' Hygiene Au Quotidien
/
L'Hygiene Au Quotidien.iso
/
mac
/
Site
/
enfants
/
images
/
score.cgi
< prev
next >
Wrap
Text File
|
2003-07-25
|
2KB
|
77 lines
#!/usr/local/bin/perl
use CGI qw(:standard -no_debug);
$name=param("name");
$score=param("score");
$scored="";
# ON TESTE LE FICHIER S'IL EXISTE
$file="scores.txt";
if(-e $file){
rename "scores.txt", "scores.bak";
$toto = open(SCORES, "scores.bak");
$nbr=0;
while($line = <SCORES>){
chop $line;
chomp $line;
@list = split(/ /, $line);
push(@noms,$list[0]." ");
push(@scor,$list[1]." ");
++$nbr;
}
chomp @noms;
chomp @scor;
close SCORES;
unlink "scores.bak";
if($nbr >= 10){$nbr=10;}
open(SCORES,">scores.bak");
for($i=0;$i<$nbr;$i++){
if($score == @scor[$i]){$scored="ok";}
if(!$scored){
if($score > @scor[$i]){
print SCORES "$name ";
print SCORES "$score\n";
print SCORES "@noms[$i]";
print SCORES "@scor[$i]\n";
$scored="ok";
}else{
print SCORES "@noms[$i]";
print SCORES "@scor[$i]\n";
}
}else{
print SCORES "@noms[$i]";
print SCORES "@scor[$i]\n";
}
}
--$i;
if(!$scored && $score>@scor[$i]){
print SCORES "$name ";
print SCORES "$score\n";
$scored="ok";
}
if(!$scored){
print SCORES "$name ";
print SCORES "$score\n";
}
close SCORES;
rename "scores.bak", "scores.txt";
# TEST DE RESULTAT
#print"<br>";print @ noms;print"<br>";print @ scor;print"<br>";print"nombre de ligne : $nbr";print"<br>";
}else{ # ...SINON ON LE CREE
open(SCORES,">scores.txt");
print SCORES "$name $score\n";
close SCORES;
}
# redirection vers la page de rΘsultats en adresse fixe
print redirect"http://localhost/resultats.html";